package com.wxh.jwt.config;

import com.wxh.jwt.interceptor.AuthenticationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName: InterceptorConfig
 * @Description:  拦截器配置类，官方推荐继承WebMvcConfigurer(可以设置静态资源)，
 * @Author wxh
 * @Date: 2020/5/28 14:40
 * @Version V1.0.0
 * @Since 1.8
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 配置我们自己定义拦截器，并实例化
     * @return
     */
    @Bean
    public AuthenticationInterceptor authenticationInterceptor(){
        return new AuthenticationInterceptor();
    }

    /**
     * 添加拦截器，将自己定义拦截器注册到spring容器中,设置拦截器的过滤路径规则。
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor()).addPathPatterns("/**");
    }
}
